package com.ycfmedical.bed.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ycfmedical.bed.R;
import com.ycfmedical.bed.bean.TextContent;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;
import cn.droidlover.xdroidmvp.kit.KnifeKit;

/**
 * Created by Administrator on 2017/2/24 0024.
 */

public class UserInfoAdapter extends SimpleRecAdapter<TextContent, UserInfoAdapter.ViewHolder> {




    public UserInfoAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_user_text;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        TextContent textContent = data.get(position);
         String title  = textContent.getTextTitle();
         String content=textContent.getTextContent();
         int drawableId=textContent.getTextDrawableId();

        setTVText(holder.textContent,content);
        setTVText(holder.textTitle,title+":");
        setTVDrawable(holder.textTitle,drawableId,context);

    }

    private void setTVDrawable(TextView textView, int drawableId,Context context) {
        if(drawableId==-1){
            return;
        }
        textView.setCompoundDrawablePadding(2);
        textView.setCompoundDrawablesWithIntrinsicBounds(context.getDrawable(drawableId),null,null,null);
    }

    private void setTVText(TextView textContent, String content) {
        if(null!=content){
            textContent.setText(content);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.textTitle)
        TextView textTitle;
        @BindView(R.id.textContent)
        TextView textContent;

        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }

}
